
import PointRoom from "../Entities/PointRoom";
import LogicConfigTs from "../Utils/LogicConfigTs";
import NotificationMgr from "../Managers/NotificationMgr";

cc.Class({
    extends: cc.Component,

    properties: {
        labelId:{
            default:null,
            type:cc.Label
        },

        labelRoomType:{
            default:null,
            type:cc.Label
        },

        labelMaxScore:{
            default:null,
            type:cc.Label
        },

        labelPrize:{
            default:null,
            type:cc.Label
        },

        prizeDetail:{
            default:null,
            type:cc.Node
        },

        labelPrize1:{
            default:null,
            type:cc.Label
        },

        labelPrize2:{
            default:null,
            type:cc.Label
        },

        prizeIconNode:{
            default:null,
            type:cc.Node
        },

        labelTimes:{
            default:null,
            type:cc.Label
        },
    },

    // LIFE-CYCLE CALLBACKS:
    

    onLoad () {
        if(this.prizeDetail) this.prizeDetail.active = false
        let isPointRoom = cc.gg.dataMgr.room instanceof PointRoom
        if(cc.gg.gameDataUtil.showRupee && isPointRoom) this.prizeIconNode.active = false
        else this.prizeIconNode.active = true
    },

    start () {

    },

    update (dt) {
        this.labelTimes.string = NotificationMgr.timesDate() ;
    },

    updateTopInfo:function (roomId, roomType, maxScore, prise) {
        let isPointRoom = cc.gg.dataMgr.room instanceof PointRoom
        if(this.labelId) this.labelId.string = "#"+roomId
        if(this.labelRoomType) this.labelRoomType.string = roomType
        if(this.labelMaxScore) this.labelMaxScore.string = isPointRoom?cc.gg.gameDataUtil.getStringOfRupee(maxScore):maxScore
        if(this.labelPrize) this.labelPrize.string = cc.gg.gameDataUtil.getStringOfRupee(prise)
    },

    initTopInfo:function (roomId, roomType, maxScore) {
        let isPointRoom = cc.gg.dataMgr.room instanceof PointRoom
        if(this.labelId) this.labelId.string = "#"+roomId
        if(this.labelRoomType) this.labelRoomType.string = roomType

        let isPractice = (cc.gg.dataMgr.room.mode & 0xf) === 0
        let rupeeStr = "0"
        if(isPointRoom && isPractice){
            rupeeStr = "₹ 0"
        }else {
            rupeeStr = isPointRoom?cc.gg.gameDataUtil.getStringOfRupee(maxScore):maxScore
        }
        if(this.labelMaxScore) this.labelMaxScore.string = rupeeStr
    },

    updatePrizeThumb:function (prizeNumber) {
        if(this.labelPrize) this.labelPrize.string = cc.gg.gameDataUtil.getStringOfRupee(prizeNumber)
    },

    updateTopInfoPrizes:function (prize1, prize2) {
        this.labelPrize1.string = cc.gg.gameDataUtil.getStringOfRupee(prize1)
        this.labelPrize2.string = cc.gg.gameDataUtil.getStringOfRupee(prize2)
    },

    onPrizeDetailClicked:function (event) {
        if(this.prizeDetail){
            this.prizeDetail.active = !this.prizeDetail.active
        }
    }
});
